package AI;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import Actor.Actor;
import Map.Floor;
import Map.Tile;
import Util.CollisionUtil;

public abstract class AbstractAI {
	protected List<Actor> actors;
	protected List<Actor> monseters;
	protected Floor map;
	Map<List<Point>, Integer> bullets;

	public AbstractAI(List<Actor> _actor, List<Actor> _monseter, Floor _map,
			Map<List<Point>, Integer> _bullets) {
		actors = _actor;
		monseters = _monseter;
		map = _map;
		bullets = _bullets;
		new Thread() {
			public void run() {
				while (true) {
					try {
						Thread.sleep(100);
						think();
						thinkAfter();
					} catch (Exception e) {

					}
				}
			}
		}.start();
	}

	public abstract void think();

	public abstract void thinkAfter();

	public void checkCollision() {
		for (Actor actor : actors) {
			for (Actor monseter : monseters) {
				if (CollisionUtil.doCollisionCheck(actor, monseter)) {
					// System.out.println("88");
				}
			}
		}
	}

	public void hitTest() {
		for (Actor _monseter : monseters) {

			List<List<Point>> removeList = new ArrayList<List<Point>>();
			for (List<Point> bullet : bullets.keySet()) {
				Integer i = bullets.get(bullet);
				Point b = bullet.get(i);
				for (int j = 0; j < 2; j++){
					for (int k = 0; k < 2; k++){
						if (b.getX() == _monseter.getX() + j
								&& b.getY() == _monseter.getY() + k) {
							System.out.println("88");
							removeList.add(bullet);
						}
					}
				}
			}
			for(List<Point> key:removeList)
				bullets.remove(key);
		}
	}
}
